/*
 * Copyright 2008 Les Hazlewood
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pojodm.party;

/**
 * @author Les Hazlewood
 * @since Apr 5, 2008 3:18:01 PM
 */
public enum Gender {

    MALE( 'M', "gender.male" ),

    FEMALE( 'F', "gender.female" );

    private char code;
    private String i18nCode = null;

    private Gender( char code, String i18nCode ) {
        this.code = code;
        this.i18nCode = i18nCode;
    }

    public String getName() {
        return name();
    }

    public char getCode() {
        return code;
    }

    public String getI18nCode() {
        return i18nCode;
    }

    public String toString() {
        return String.valueOf(getCode());
    }

    public static Gender fromCode( char code ) {
        switch ( code ) {
            case 'M': case 'm': return Gender.MALE;
            case 'F': case 'f': return Gender.FEMALE;
            default: throw new IllegalArgumentException( "Invalid Gender code [" + code + "].  Valid values: " +
                    "'M', 'm', 'F', 'f'." );
        }
    }

    public static Gender fromCode( String code) {
        if ( code == null ) {
            throw new IllegalArgumentException( "code argument cannot be null" );
        }
        return fromCode(code.charAt(0));
    }
}
